package com.itheima.zixi1.ZuoYe.ZuoYe3;

public class test {
    public static void main(String[] args) {
        Card silvercard = new SilverCard("2",2000);
        Card goldcard = new GoldCard("1",1000);
        paymoney(silvercard,200);
        paymoney(goldcard,200);
    }
    public static void paymoney(Card card,double money){
        if(card instanceof SilverCard){
            double p = card.pay(money);
            System.out.println("您需要支付的金额为:"+p);
            if(card.getBalance()>=p){
                card.setBalance(card.getBalance()-p);
                System.out.println("支付成功,支付后金额为："+card.getBalance());
            }else{
                System.out.println("支付失败,余额不足");
            }

        }
        if(card instanceof GoldCard){
            double p = card.pay(money);
            System.out.println("您需要支付的金额为:"+p);
            if(card.getBalance()>=p){
                card.setBalance(card.getBalance()-p);
                System.out.println("支付成功,支付后金额为："+card.getBalance());
            }else{
                System.out.println("支付失败,余额不足");
            }

        }
    }
}
